package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoAnnotation;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     *
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    @AutoAnnotation(OperationType.INSERT)
    Integer countByCategoryId(Long id);

    @AutoAnnotation(OperationType.INSERT)
    void insert(Setmeal setmeal);

    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    @Select("select *from setmeal where id= #{id}")
//根据套餐id查套餐
    Setmeal getById(Long id);

    @Delete("delete from setmeal where id=#{id}")
//根据id删除
    void deleteBySetmealId(Long setmealId);

    //修改套餐
    void update(Setmeal setmeal);
//小程序用户查套餐
    List<Setmeal> list(Setmeal setmeal);
//小程序根据套餐展示菜品
    @Select("select sd.name ,sd.copies,d.image,d.description from d.name setmeal_dish sd left dish d on sd.dish_id=d.id where sd.setmeal_id=#{setmealId}   ")
    List<DishItemVO> getDishItemBySetmealId(Long id);
    @Select("select * from setmeal where id = #{id}")
    Setmeal queryById(Long id);

    Integer countByMap(Map map);
}
